﻿using System;
using GeoAPI.Geometries;

namespace YJKGridTopologyCal.Mathematics
{
	public class Plane3D
	{
		public Plane3D(Vector3D normal, Coordinate basePt)
		{
			this._normal = normal;
			this._basePt = basePt;
		}

		public double OrientedDistance(Coordinate p)
		{
			double num = new Vector3D(p, this._basePt).Dot(this._normal);
			if (double.IsNaN(num))
			{
				throw new ArgumentException("3D Coordinate has NaN ordinate");
			}
			return num / this._normal.Length();
		}

		public Plane ClosestAxisPlane()
		{
			double num = Math.Abs(this._normal.X);
			double num2 = Math.Abs(this._normal.Y);
			double num3 = Math.Abs(this._normal.Z);
			if (num > num2)
			{
				if (num > num3)
				{
					return Plane.YZ;
				}
				return Plane.XY;
			}
			else
			{
				if (num3 > num2)
				{
					return Plane.XY;
				}
				return Plane.XZ;
			}
		}

		private readonly Vector3D _normal;

		private readonly Coordinate _basePt;
	}
}
